package com.qf.medicaldoctoradmin.onlineSigning.nearbyMechanism.service.impl;

import com.qf.common.entity.Institution;
import com.qf.medicaldoctoradmin.onlineSigning.nearbyMechanism.dao.OrganizationDao;
import com.qf.medicaldoctoradmin.onlineSigning.nearbyMechanism.vo.OrganizationVO;
import com.qf.medicaldoctoradmin.onlineSigning.nearbyMechanism.vo.SearchVO;
import com.qf.medicaldoctoradmin.onlineSigning.nearbyMechanism.service.OrganizationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class OrganizationServiceImpl implements OrganizationService {

    @Resource
    private OrganizationDao organizationDao;
    @Override
    public List<OrganizationVO> selectList() {
        List<Institution> institutionList = organizationDao.selectList(null);
//        OrganizationParam param = new OrganizationParam();
//        List<OrganizationParam> list = new ArrayList<>();
//        institutionList.stream().forEach(item ->{
//            BeanUtils.copyProperties(item,param);
//            list.add(param);
//        });

        return institutionList.stream()
                .map(this::convertToOrganizationParam)
                .collect(Collectors.toList());
    }

    @Override
    public List<SearchVO> searchByName(String keyword) {
        List<SearchVO> list = organizationDao.selectByDoctorOrOrganizationName(keyword);
        return list;
    }

    // 转换方法，将Institution转换为OrganizationParam
    private OrganizationVO convertToOrganizationParam(Institution institution) {
        OrganizationVO organizationParam = new OrganizationVO();
        organizationParam.setId(institution.getId());
        organizationParam.setCoverImg(institution.getCoverImg());
        organizationParam.setLocation(institution.getLocation());
        organizationParam.setName(institution.getName());
        return organizationParam;
     }



    }


